package com.example.dao;

import com.example.entity.BackendApi;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BackendApiDao {

    @Select("SELECT * FROM backend_apis")
    List<BackendApi> getAllApis();
    
    @Select("SELECT * FROM backend_apis WHERE id = #{id}")
    BackendApi getApiById(int id);
    
    @Insert("INSERT INTO backend_apis(name, method, path, description, created_at, updated_at) " +
            "VALUES(#{name}, #{method}, #{path}, #{description}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertApi(BackendApi backendApi);
    
    @Update("UPDATE backend_apis SET name = #{name}, method = #{method}, path = #{path}, " +
            "description = #{description}, updated_at = NOW() WHERE id = #{id}")
    int updateApi(BackendApi backendApi);
    
    @Delete("DELETE FROM backend_apis WHERE id = #{id}")
    int deleteApi(int id);
    
    @Select("SELECT * FROM backend_apis WHERE name LIKE CONCAT('%', #{name}, '%')")
    List<BackendApi> searchApisByName(String name);
}
